
package com.joysuch.wwyt.datasync.service;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.joysuch.wwyt.bp.entity.*;
import com.joysuch.wwyt.bp.entity.contractor.*;
import com.joysuch.wwyt.bp.entity.inspect.BpInspectRecordDetail;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigatePlan;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigateRecord;
import com.joysuch.wwyt.core.entity.BaseUser;
import com.joysuch.wwyt.edu.entity.EduCertificateUser;
import com.joysuch.wwyt.edu.entity.EduTrainningPlan;
import com.joysuch.wwyt.edu.entity.EduTrainningRecord;
import com.joysuch.wwyt.edu.entity.EduTrainningRecordUser;
import com.joysuch.wwyt.mh.entity.MhMajorHazardChemProduct;
import com.joysuch.wwyt.risk.entity.*;
import com.joysuch.wwyt.workflow.entity.WorkFlowTask;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataSyncRegister {

    private static Map<String, String> serviceNameMap = new HashMap<>();

    public static void loadFromJson(InputStream input) throws Exception {
        List<HashMap> list = new Gson().fromJson(new InputStreamReader(input, "utf-8"), new TypeToken<List<HashMap>>() {
        }.getType());

        for(HashMap h: list) {
            String className = (String) h.get("class");
            String serviceId = (String) h.get("serviceId");
            add(Class.forName(className), serviceId);
        }
    }

    public static void add(Class clzz, String serviceName) {
        serviceNameMap.put(clzz.getName(), serviceName);
    }

    public static String get(Class clzz) {
        return serviceNameMap.get(clzz.getName());
    }

    public static String remove(Class clzz) {
        return serviceNameMap.remove(clzz.getName());
    }

    public static void clear() {
        serviceNameMap.clear();
    }
}
